#include <bits/stdc++.h>
using namespace std;

const int n = 7;
int sgn(int x) { return (x > 0) - (x < 0);}

int ans = 0x7fffffff;

struct node {
    set<int> S;
    vector<int> v;
    int cur;
    node() {
        S.clear();
        S.insert(0);
        v.clear();
        cur = 0;
    }
    inline bool check(int v) {
        for (int x : S) {
            if (S.count(x + v)) return false;
            if (S.count(abs(x - v)) && (x + x != v)) return false;
        }

        int n = this->v.size();
        int sum1 = this->v[0], sum2 = v;
        for (int i=1; i<n; ++i) {
            sum1 += this->v[i];
            if (i > 1) sum2 += this->v[n-i+1];
            if (sum1 < sum2) return false;
        }
        return true;
    }

    void insert(int newv) {
        v.push_back(newv);
        vector<int> tmp;
        for (int x : S) tmp.push_back(x);
        for (int x : tmp) S.insert(x + newv);
        cur += newv;
    }
} ansn;



void dfs(node now, int dep) {
    assert(now.v.size() == dep);
    if (now.cur >= ans) return;
    if (dep == n) {
        ans = now.cur;
        ansn = now;
        return;
    }


    for (int i=now.v.back() + 1; i < now.v[0] + now.v[1]; ++i) {
        if (!now.check(i)) continue;
        node newnode = now;
        newnode.insert(i);
        dfs(newnode, dep+1);
    }
}

namespace judge {
    vector<pair<int, int> > tmp;
    void dfs(const vector<int> &v, int dep, int ans, int num) {
        if (dep == v.size()) {
            tmp.push_back({ans, num});
            return;
        }
        dfs(v, dep+1, ans + v[dep], num+1);
        dfs(v, dep+1, ans, num);
    }

    bool valid(const vector<int> &v) {
        tmp.clear();
        fprintf(stderr, "v.size() -> %d\n", v.size());
        dfs(v, 0, 0, 0);
        int n = tmp.size();
        for (int i=0; i<n; ++i)
        for (int j=i+1; j<n; ++j) {
            if (tmp[i].first == tmp[j].first) {
                fprintf(stderr, "err: two subsets eq: %d\n", tmp[i].first);
                return false;
            }
            if (sgn(tmp[i].first - tmp[j].first) * sgn(tmp[i].second - tmp[j].second) < 0) {
                fprintf(stderr, "err: two subsets not valid: %d %d, %d %d\n", tmp[i].first, tmp[i].second, tmp[j].first, tmp[j].second);
                return false;
            }
        }
        fprintf(stderr, "checked subset: %d\n", n);
        return true;
    }
}

int main(int argc, char const *argv[])
{
    for (int i=1; i<=40; ++i) {
        for (int j=i+1; j<=50; ++j) {
            fprintf(stderr, "dbg: i=%d, j=%d\n", i, j);
            node now;
            now.insert(i);
            now.insert(j);
            dfs(now, 2);
        }
    }
    printf("%d\n", ans);
    for (int v : ansn.v) printf("%d", v);
    puts("");
    // ansn.v.pop_back();
    fprintf(stderr, "verdict: %d\n", judge::valid(ansn.v));
    return 0;
}
